# 383.赎金信
# 给你两个字符串：ransomNote和magazine ，判断ransomNote能不能由magazine里面的字符构成。
# 如果可以，返回true ；否则返回false 。
# magazine中的每个字符只能在ransomNote中使用一次。
#
#
# 示例1：
# 输入：ransomNote = "a", magazine = "b"
# 输出：false
#
# 示例2：
# 输入：ransomNote = "aa", magazine = "ab"
# 输出：false
#
# 示例3：
# 输入：ransomNote = "aa", magazine = "aab"
# 输出：true


class Solution:
    def canConstruct(self, ransomNote: str, magazine: str) -> bool:
        dic = {}
        for i in ransomNote:
            if i not in dic:
                dic[i] = 1
            else:
                dic[i] += 1
        dic_mag = {}
        for j in magazine:
            if j not in dic_mag:
                dic_mag[j] = 1
            else:
                dic_mag[j] += 1
        for k, v in dic.items():
            tmp = dic_mag.get(k)
            if tmp is None or v > tmp:
                return False
        return True

if __name__ == '__main__':
    ransomNote = "aa"
    magazine = "aab"
    tmp = Solution()
    res = tmp.canConstruct(ransomNote,magazine)
    print(res)
